//
//  ViewController.swift
//  CoolImageFound
//
//  Created by  iBrother 李彦兵 on 2018/6/9.
//  Copyright © 2018  iBrother 李彦兵. All rights reserved.
//

import UIKit

class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

    var flowLayout: ColumnFlowLayout!
    var collectionView: UICollectionView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        flowLayout = ColumnFlowLayout()
        collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: flowLayout)
        collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        collectionView.backgroundColor = UIColor.black
        collectionView.alwaysBounceVertical = true
        collectionView.delegate = self
        collectionView.dataSource = self
        view.addSubview(collectionView)
        
        let nib = UINib(nibName: "PersonCell", bundle: nil)
        collectionView.register(nib, forCellWithReuseIdentifier: "PersonCell")
    }


    // MARK: Datesource
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PersonCell", for: indexPath)
        
        return cell
    }
    
 
    // MARK: Delegate
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        guard let navController = self.navigationController else {
            return
        }
        let feedViewController = FeedViewController()
        navController.pushViewController(feedViewController, animated: true)
    }
}

